home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 4 / QRZ Ham Radio Callsign Database - Volume 4.iso / files / tcpip / amiga / asrc29p.lha / gendom.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-29  |  1.4 KB  |  61 lines

  1. /* Here is a program to convert your hosts.net to domain.txt */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <ctype.h>
  5. #include <string.h>
  6.  
  7. #define LINELEN 256
  8. /* copyright 1989 - John D. Hays, KD7UW */
  9. /*           1991 - John Heaton,  G1YYH */
  10. main(int argc,char *argv[])
  11. {
  12.  
  13.     FILE *fi,*fo;
  14.     char string[LINELEN-1];
  15.     char addr[20],hname1[80],hname2[80];
  16.     char *x,*y,*z;
  17.  
  18.     fprintf(stderr,"COPYRIGHT 1989/91 - KD7UW/G1YYH\n");
  19.     if (argc <= 2) {
  20.         fprintf(stderr,"Usage: %s <Hosts.NET> <Domain.TXT> <FULL>\n\007",argv[0]);
  21.         exit(0);
  22.     }
  23.  
  24.     if ((fi=fopen(argv[1],"r")) != NULL) {
  25.         fo = fopen(argv[2],"w");
  26.         while (fgets(string,LINELEN,fi) != NULL) {
  27.             y = strchr(string,'\n');
  28.             *y = '\0';
  29.             addr[0] = '\0';
  30.             hname1[0] = '\0';
  31.             hname2[0] = '\0';
  32.             if ((string[0] == '#') || (strlen(string) < 3)) {
  33.                 fprintf(fo,"%s\n",string);
  34.             } else {
  35.                 y = strchr(string,'#');
  36.                 if (y != NULL) {
  37.                     if (argv[3] != NULL)
  38.                         fprintf(fo,"#%s\n",y);
  39.                     *y = '\0';
  40.                 }
  41.                 sscanf(string,"%s%s%s",addr,hname1,hname2);
  42.                 fprintf(stderr,"%16s\r",addr);
  43.                 if (strchr(hname1,'.'))    {
  44.                     x = hname1;
  45.                     z = hname2;
  46.                 } else {
  47.                     x = hname2;
  48.                     z = hname1;
  49.                 }
  50.                 if ((*x == '\0') || (*z == '\0')) {
  51.                     fprintf(fo,"%s.\tIN\tA\t%s\n",hname1,addr);
  52.                 } else {
  53.                     if (argv[3] != NULL)
  54.                         fprintf(fo,"%s.\tIN\tCNAME\t%s.\n",z,x);
  55.                     fprintf(fo,"%s.\tIN\tA\t%s\n",x,addr);
  56.                 }
  57.             }
  58.         }
  59.     }
  60. }
  61.